﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Threading;
using System.Reflection; // 引用这个才能使用Missing字段
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using CCWin;

namespace weiqijiance.安检仪表
{
    public partial class diaodu : Form
    {
        public mainform m_mainform;
        string zjhphm = "";
        string zjhpzl = "";
        string sptjylsh="";
        string businessId = "";
        string methodId = "";
        string sdetid = "";
        string sdlxjy = "";
        string syhjy = "";
        string shphm = "";
        string shpzl = "";
        string jccs = "";
        string testtimes = "";
        string sobdshifou = "";
        string obdzt = "";
        string sgkfjc = "";
        public flowAP objap1 = new flowAP();
        public flowAP objap2 = new flowAP();
        public flowAP objap3 = new flowAP();

        #region 控件大小随窗体大小等比例缩放
        private float x;//定义当前窗体的宽度
        private float y;//定义当前窗体的高度
        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            if (newy <= 0)
            {
                newy = 1;
            }

            //遍历窗体中的控件，重新设置控件的值
            foreach (Control con in cons.Controls)
            {
                //获取控件的Tag属性值，并分割后存储字符串数组
                if (con.Tag != null)
                {
                    string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
                    //根据窗体缩放的比例确定控件的值
                    con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
                    con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
                    con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
                    con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
                    Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                    if (con.Controls.Count > 0)
                    {
                        setControls(newx, newy, con);
                    }
                }
            }
        }
        void Form1_Resize(object sender, EventArgs e)
        {
            float newx = (this.Width) / x;
            float newy = (this.Height) / y;
            setControls(newx, newy, this);
        }
        #endregion
        public diaodu()
        {
            //contextMenuStrip2.Show();
            InitializeComponent();
            this.Resize += new EventHandler(Form1_Resize);
            x = this.Width;
            y = this.Height;
            setTag(this);
        }
        private void diaodu_Load(object sender, EventArgs e)
        {
            iniYCY("YCY");
            iniCZY("CZY");
            iniYCY2("YCY");
            iniCZY2("CZY");
            iniYCY3();
            iniYCYzj();
            getdongtai();
            objap1.objdd = this;
            objap2.objdd = this;
            objap3.objdd = this;
            //iniaps();
        }

        public void iniYCY(string dataname)
        {

            string ssqlex = "";
            //ssqlex = string.Format(@"select * from {0}", dataname);
            ssqlex = string.Format(@"select * from Employee where EP_TYPE ='引车员'");
            DataTable dt = m_mainform.objbass.objdb.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                skinCom_ycy.Items.Add(dt.Rows[i]["EP_NAME"].ToString().Trim());
                //skinCom_ycy.Items.Add(dt.Rows[i]["name"].ToString().Trim());
                if (i == 0)
                    skinCom_ycy.Text = dt.Rows[0]["EP_NAME"].ToString().Trim();
                    //skinCom_ycy.Text = dt.Rows[0]["name"].ToString().Trim();
            }
        }

        public void iniCZY(string dataname)
        {

            string ssqlex = "";
            //ssqlex = string.Format(@"select * from {0}", dataname);
            ssqlex = string.Format(@"select * from Employee where EP_TYPE ='操作员'");
            DataTable dt = m_mainform.objbass.objdb.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                skinCom_czy.Items.Add(dt.Rows[i]["EP_NAME"].ToString().Trim());
                //skinCom_czy.Items.Add(dt.Rows[i]["name"].ToString().Trim());
                if (i == 0)
                    //skinCom_czy.Text = dt.Rows[0]["name"].ToString().Trim();
                    skinCom_czy.Text = dt.Rows[0]["EP_NAME"].ToString().Trim();
            }
        }

        public void iniYCY2(string dataname)
        {

            string ssqlex = "";
            ssqlex = string.Format(@"select * from Employee where EP_TYPE ='引车员'");
            //ssqlex = string.Format(@"select * from {0}", dataname);
            DataTable dt = m_mainform.objdbbass.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //skinCom_ycy2.Items.Add(dt.Rows[i]["name"].ToString().Trim());
                skinCom_ycy2.Items.Add(dt.Rows[i]["EP_NAME"].ToString().Trim());
                if (i == 0)
                    //skinCom_ycy2.Text = dt.Rows[0]["name"].ToString().Trim();
                    skinCom_ycy2.Text = dt.Rows[0]["EP_NAME"].ToString().Trim();
            }
        }
        public void iniYCY3()//底盘检验员
        {

            string ssqlex = "";
            ssqlex = string.Format(@"select * from USERE where JSLX ='底盘检验员'");
            DataTable dt = m_mainform.objdbbass.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                com_czy.Items.Add(dt.Rows[i]["NAME"].ToString().Trim());
                if (i == 0)
                    com_czy.Text = dt.Rows[0]["NAME"].ToString().Trim();
            }
        }

        public void iniCZY2(string dataname)
        {

            string ssqlex = "";
            //ssqlex = string.Format(@"select * from {0}", dataname);
            ssqlex = string.Format(@"select * from Employee where EP_TYPE ='操作员'");
            DataTable dt = m_mainform.objdbbass.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //skinCom_czy2.Items.Add(dt.Rows[i]["name"].ToString().Trim());
                skinCom_czy2.Items.Add(dt.Rows[i]["EP_NAME"].ToString().Trim());
                if (i == 0)
                    //skinCom_czy2.Text = dt.Rows[0]["name"].ToString().Trim();
                    skinCom_czy2.Text = dt.Rows[0]["EP_NAME"].ToString().Trim();
            }
        }

        private void skinBut_chaxun_Click(object sender, EventArgs e)
        {
            string sstart = datestart.Value.ToString("yyyy-MM-dd 00:00:00");
            string send = dateend.Value.ToString("yyyy-MM-dd 23:59:59");
            m_mainform.objbass = m_mainform.objbassLW;
            getjiluSQL(text_hphm.Text, true, skinDataGridView_wj, sstart, send);//获取登录车辆上线
        }

        private void skinBut_shuaxin_Click(object sender, EventArgs e)
        {

            m_mainform.objbass = m_mainform.objbassLW;
            try
            {
                string sss = "exec sp_rename 'YJHJ03.JCWC','JCWCEX'";
                m_mainform.objbass.objdb.InsertDB(sss);
            }
            catch (Exception )
            { }
            try
            {
                string sss = "exec sp_rename 'BYclxxex.jcwc','jcwcex'";
                m_mainform.objbass.objdb.InsertDB(sss);
            }
            catch (Exception )
            {

            }
            string sstart = datestart.Value.ToString("yyyy-MM-dd 00:00:00");
            string send = dateend.Value.ToString("yyyy-MM-dd 23:59:59");
            m_mainform.objbass = m_mainform.objbassLW;
            getjiluSQL("", false, skinDataGridView_wj, sstart, send);//获取登录车辆上线
            //getjiluSQL("", false, skinDataGridView_wj);//获取登录车辆上线
        }

        public bool getdatezj(string sdate)
        {
            DateTime dtimezj = DateTime.Now;
            DateTime.TryParse(sdate, out dtimezj);
            if ((DateTime.Now - dtimezj).TotalDays > 1)
            {
                return false;
            }
            return true;
            //if (DateTime.TryParse(stimehxqy, out hxdtime) && DateTime.TryParse(stimeyqfq, out hxdtime))
            //{
            //    if ((DateTime.Now - hxdtime).TotalDays > 1)
            //    {
            //        HXqy = false;
            //        bzijian = false;
            //    }
            //}
        }
        public bool getzijian(string methodId)
        {


            string paths = "";
            paths = System.Windows.Forms.Application.StartupPath + paths + "\\系统信息.ini";
            string path2 = string.Format(@"{0}", paths);
            iniclass objini = new iniclass();
            objini.Ini(path2);
            string fenxiyinameQY = objini.ReadValue("串口设置", "废气仪厂家");
            string fenxiyinameCY = objini.ReadValue("串口设置", "不透光厂家");

            string path = "";
            string stimehxqy = "";
            string stimehxcy = "";
            string stimeyr = "";
            string stimeyqfq = "";
            string stimeyqbtg = "";
            string stimeyqcaiyou = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\设备检定结果.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);
            stimehxqy = objini.ReadValue("汽油恒加载检定", "检定时间");
            stimehxcy = objini.ReadValue("柴油加载滑行10kw", "检定时间");
            stimeyqfq = objini.ReadValue("废气仪检定", "检定时间");
            stimeyqbtg = objini.ReadValue("不透光检定", "检定时间");
            stimeyr = objini.ReadValue("台架预热", "检定时间");
            stimeyqcaiyou = objini.ReadValue("柴油分析仪检定", "检定时间");
            string smessagebox = "";
            if (methodId.Contains("DB") || methodId.Contains("双怠速") || methodId.Contains("WT") || methodId.Contains("ASM"))//shaungdaishu双怠速
            {
                bool bzj = true;
                smessagebox = "系统已经被锁止，你需要做以下自检进行解锁：\r\n";
                if (!getdatezj(stimehxqy))
                {
                    smessagebox += "测功机自检\r\n";
                    bzj = false;
                }
                if (!getdatezj(stimeyqfq))
                {
                    smessagebox += "五气分析仪自检\r\n";
                    bzj = false;
                }
                if (!bzj)
                {
                    MessageBox.Show(smessagebox);
                    return false;
                }
            }
            else if (methodId.Contains("LD") || methodId.Contains("加载") || methodId.Contains("TG") || methodId.Contains("自由"))//LUG
            {
                bool bzj = true;
                smessagebox = "系统已经被锁止，你需要做以下自检进行解锁：\r\n";
                if (!getdatezj(stimehxcy))
                {
                    smessagebox += "测功机自检\r\n";
                    bzj = false;
                }
                if (!getdatezj(stimeyqbtg))
                {
                    smessagebox += "不透光烟度计自检\r\n";
                    bzj = false;
                }
                if (!getdatezj(stimeyqcaiyou))
                {
                    smessagebox += "氮氧自检\r\n";
                    bzj = false;
                }
                if (!bzj)
                {
                    MessageBox.Show(smessagebox);
                    return false;
                }
            }
            return true;
        }
        public bool bsuozhi = true;
        private void skinBut_shangxian_Click(object sender, EventArgs e)
        {
            if (m_mainform.bsuozhi)
            {
                if (!getzijian(methodId))
                {
                    //if (bsuozhi)
                    return;
                }
            }
            m_mainform.initobdgcsj();
            m_mainform.objbass = m_mainform.objbassLW;
            m_mainform.bdiaodu = true;
            mainform.methodId = methodId;
            mainform.shphm = shphm;
            mainform.shpzl = shpzl;
            m_mainform.sobdshifou = sobdshifou;
            mainform.businessId = businessId;
            m_mainform.testtimes = testtimes;
            m_mainform.sfOBD = false;
            m_mainform.InspectionOperator = skinCom_czy.Text;
            m_mainform.InspectionDriver = skinCom_ycy.Text;
            mainform.obdzt = obdzt;
            //baocunCLXX(string hphm, string hpzl, string edgl, string edzs, string jzzl,string cllx)
            bcclxx(businessId);//保存车辆信息，智慧
            if (!m_mainform.sconnetname.Contains("安车"))
            {
                m_mainform.objbass.sendOBDJCJG(businessId);
            }
            if (m_mainform.objbass.baocunclexxyj(businessId).Contains("0"))//冯文健加
                return;
            m_mainform.objbass.getstandxz(businessId);
            m_mainform.objbass.setclxx(businessId);//获取车辆信息 邦元的必须放在获取限值后面
            //objbass.getstandxz(shphm, shpzl, skinCom_ycy.Text, skinCom_czy.Text);//获取限值
            m_mainform.inserttongji(businessId, shphm, testtimes);//更新插入TONGJI表
            m_mainform.StartTest(methodId);
        }

        private void skinBut_time_Click(object sender, EventArgs e)
        {
            m_mainform.objbass = m_mainform.objbassLW;
            m_mainform.objbass.gettime();
        }

        private void skinButton3_Click(object sender, EventArgs e)
        {
            seachlistview(textBox1.Text, dateTimePicker2.Value.ToString("yyyy-MM-dd"), dateTimePicker1.Value.ToString("yyyy-MM-dd"));
        }

        private void skinButton4_Click(object sender, EventArgs e)
        {
            m_mainform.bdiaodu = true;
            if (string.IsNullOrWhiteSpace(sdetid))
            {
                MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                return;
            }
            if (sdlxjy != "是")
            {
                MessageBox.Show("动力性检测免检");
                return;
            }
            m_mainform.objyibiaobass.select("动力性");
            //flowdlx.flowbass.sDetectID = sdetid;
            //flowdlx.ShowDialog();
        }

        private void skinButton5_Click(object sender, EventArgs e)
        {

            m_mainform.bdiaodu = true;
            if (string.IsNullOrWhiteSpace(sdetid))
            {
                MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                return;
            }
            if (syhjy != "是")
            {
                MessageBox.Show("油耗检测免检");
                return;

            }
            m_mainform.objyibiaobass.select("油耗");
            //flowyh.flowbass.sDetectID = sdetid;
            //flowyh.ShowDialog();
        }

        private void skinDataGridView_wj_SelectionChanged(object sender, EventArgs e)
        {

            //try
            //{
            //    businessId = this.skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString();
            //    methodId = this.skinDataGridView_wj.CurrentRow.Cells[3].Value.ToString();
            //    shphm = this.skinDataGridView_wj.CurrentRow.Cells[1].Value.ToString();
            //    shpzl = this.skinDataGridView_wj.CurrentRow.Cells[2].Value.ToString();
            //    jccs = this.skinDataGridView_wj.CurrentRow.Cells[5].Value.ToString();
            //    testtimes = this.skinDataGridView_wj.CurrentRow.Cells[5].Value.ToString();
            //    if (this.skinDataGridView_wj.CurrentRow.Cells[4].Value.ToString().Trim().Length > 0)
            //    {
            //        sobdshifou = "1";
            //    }
            //    else
            //    {
            //        sobdshifou = "0";
            //    }

            //    if (methodId.Contains("WT") || methodId.Contains("ASM") || methodId.Contains("LD") || methodId.Contains("加载"))//ASM
            //    {
            //        sgkfjc = "1";
            //    }
            //    else
            //    {
            //        sgkfjc = "0";
            //    }

            //}
            //catch
            //{
            //}
        }

        private void dgvzongjian_SelectionChanged(object sender, EventArgs e)
        {

            //try
            //{
            //    sdetid = "";
            //    sdlxjy = "";
            //    syhjy = "";
            //    sdetid = this.dgvzongjian.CurrentRow.Cells[0].Value.ToString();
            //    sdlxjy = this.dgvzongjian.CurrentRow.Cells[3].Value.ToString();
            //    syhjy = this.dgvzongjian.CurrentRow.Cells[4].Value.ToString();
            //}
            //catch
            //{
            //}
        }


        public void getjiluSQL(string shphm, bool bbz, CCWin.SkinControl.SkinDataGridView objsdgv, string sstart, string send)//获取登录车辆上线
        {

            objsdgv.Rows.Clear();
            //string sstart = datestart2.Value.ToString("yyyy-MM-dd 00:00:00");
            //string send = dateend2.Value.ToString("yyyy-MM-dd 23:59:59");
            DataTable dt = m_mainform.objbass.getjilu(shphm, sstart, send, bbz);
            if (dt.Rows.Count > 0)
            {
                objsdgv.Rows.Add(dt.Rows.Count + 1);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    objsdgv.Rows[i].Cells[0].Value = dt.Rows[i]["DETECT_ID"].ToString().Trim();    //填充第一列的数据 
                    objsdgv.Rows[i].Cells[1].Value = dt.Rows[i]["PLATE_ID"].ToString().Trim();    //填充第二列的数据 
                    objsdgv.Rows[i].Cells[2].Value = dt.Rows[i]["PCLASS_ID"].ToString().Trim();    //填充第二列的数
                    objsdgv.Rows[i].Cells[3].Value = dt.Rows[i]["jcff"].ToString().Trim(); ;    //填充第二列的数据 据 
                    objsdgv.Rows[i].Cells[4].Value = dt.Rows[i]["OBD"].ToString().Trim(); ;    //填充第二列的数据 
                    objsdgv.Rows[i].Cells[5].Value = dt.Rows[i]["jccs"].ToString().Trim(); ;    //填充第二列的数据 
                    objsdgv.Rows[i].Cells[6].Value = dt.Rows[i]["zt"].ToString().Trim(); ;    //填充第二列的数据 
                }

                try
                {
                    //MessageBox.Show(this.skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString());
                    businessId = objsdgv.Rows[0].Cells[0].Value.ToString();
                    methodId = objsdgv.Rows[0].Cells[3].Value.ToString();
                    shphm = objsdgv.Rows[0].Cells[1].Value.ToString();
                    shpzl = objsdgv.Rows[0].Cells[2].Value.ToString();
                    jccs = objsdgv.Rows[0].Cells[5].Value.ToString();
                    testtimes = objsdgv.Rows[0].Cells[5].Value.ToString();
                    obdzt = objsdgv.Rows[0].Cells[4].Value.ToString();
                }
                catch
                {
                }
            }
        }

        //--新增综检查询
        public void seachlistview(string hphm, string date1, string date2)
        {
            dgvzongjian.Rows.Clear();
            string ssql = string.Format(@"SELECT * from AUTO,Detects_SJA where AUTO.AT_ID=Detects_SJA.AT_ID 
 and Detects_SJA.DET_DATE>'{0}' and Detects_SJA.DET_DATE<dateadd(day,1,'{1}') and AUTO.AT_HPHM like '%{2}%' order by Detects_SJA.DETECT_ID",
date1, date2, hphm);

            DataTable dt = m_mainform.objbass.objdb.GetTable(ssql);
            int count = 0;
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["DET_JCLB"].ToString().Trim().Contains("等级评定"))
                    {
                        int iitem = 0;
                        if (!int.TryParse(dr["DET_JYCS"].ToString().Trim(), out iitem))
                            iitem = 0;
                        this.dgvzongjian.Rows.Add();
                        this.dgvzongjian.Rows[count].Cells[0].Value = dr["DETECT_ID"].ToString().Trim();    //填充第一列的数据 
                        this.dgvzongjian.Rows[count].Cells[1].Value = dr["AT_HPHM"].ToString().Trim();    //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[2].Value = dr["AT_HPZL"].ToString().Trim();    //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[3].Value = dr["DET_BJYXM"].ToString().Trim().Contains("DLX") ? "是" : "否";     //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[4].Value = dr["DET_BJYXM"].ToString().Trim().Contains("RYJJX") ? "是" : "否";     //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[5].Value = iitem;//(iitem + 1).ToString();    //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[6].Value = dr["DET_BJYXM"].ToString().Trim().Contains("M1") ? "是" : "否";     //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[7].Value = dr["DET_BJYXM"].ToString().Trim().Contains("Z1") ? "是" : "否";     //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[8].Value = dr["DET_BJYXM"].ToString().Trim().Contains("C1") ? "是" : "否";     //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[9].Value = dr["DET_LSH"].ToString().Trim();     //填充第二列的数据 
                        if (dr["DET_EJYXM"].ToString().Trim().Contains("C1"))
                        {
                            this.dgvzongjian.Rows[count].Cells[8].Style.ForeColor = Color.Red;
                        }
                        count++;
                    }
                    else if (dr["DET_BJYXM"].ToString().Trim().Contains("M1") || dr["DET_BJYXM"].ToString().Trim().Contains("Z1") || dr["DET_BJYXM"].ToString().Trim().Contains("C1"))
                    {
                        int iitem = 0;
                        if (!int.TryParse(dr["DET_JYCS"].ToString().Trim(), out iitem))
                            iitem = 0;
                        this.dgvzongjian.Rows.Add();
                        this.dgvzongjian.Rows[count].Cells[0].Value = dr["DETECT_ID"].ToString().Trim();    //填充第一列的数据 
                        this.dgvzongjian.Rows[count].Cells[1].Value = dr["AT_HPHM"].ToString().Trim();    //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[2].Value = dr["AT_HPZL"].ToString().Trim();    //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[3].Value = dr["DET_BJYXM"].ToString().Trim().Contains("DLX") ? "是" : "否";     //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[4].Value = dr["DET_BJYXM"].ToString().Trim().Contains("RYJJX") ? "是" : "否";     //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[6].Value = dr["DET_BJYXM"].ToString().Trim().Contains("M1") ? "是" : "否";     //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[7].Value = dr["DET_BJYXM"].ToString().Trim().Contains("Z1") ? "是" : "否";     //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[5].Value = iitem;    //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[8].Value = dr["DET_BJYXM"].ToString().Trim().Contains("C1") ? "是" : "否";     //填充第二列的数据 
                        this.dgvzongjian.Rows[count].Cells[9].Value = dr["DET_LSH"].ToString().Trim();     //填充第二列的数据 
                        if (dr["DET_EJYXM"].ToString().Trim().Contains("M1"))
                        {
                            this.dgvzongjian.Rows[count].Cells[6].Style.ForeColor = Color.Red;
                        }
                        if (dr["DET_EJYXM"].ToString().Trim().Contains("Z1"))
                        {
                            this.dgvzongjian.Rows[count].Cells[7].Style.ForeColor = Color.Red;
                        }
                        if (dr["DET_EJYXM"].ToString().Trim().Contains("C1"))
                        {
                            this.dgvzongjian.Rows[count].Cells[8].Style.ForeColor = Color.Red;
                        }
                        count++;
                    }
                }
                if (count > 0)
                {
                    try
                    {
                        sdetid = this.dgvzongjian.Rows[0].Cells[0].Value.ToString();
                        sdlxjy = this.dgvzongjian.Rows[0].Cells[3].Value.ToString();
                        syhjy = this.dgvzongjian.Rows[0].Cells[4].Value.ToString();
                        sdetid = "";
                        sdlxjy = "";
                        syhjy = "";
                        sptjylsh = "";
                        sptjylsh = this.dgvzongjian.Rows[0].Cells[9].Value.ToString();
                        zjhphm = this.dgvzongjian.Rows[0].Cells[1].Value.ToString();
                        zjhpzl = this.dgvzongjian.Rows[0].Cells[2].Value.ToString();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
                else
                {
                    MessageBox.Show("该工位查询记录为空");
                }

            }
            else
            {
                MessageBox.Show("查询记录为空");
            }

        }

        private void skinButton1_Click(object sender, EventArgs e)
        {

            if (string.IsNullOrWhiteSpace(sdetid))
            {
                MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                return;
            }
            m_mainform.flowzbzl.flowbass.sDetectID = sdetid;
            m_mainform.flowzbzl.flowbass.IsReadyForStart();
            if (m_mainform.flowzbzl.flowbass.sPclass.Contains("挂") || m_mainform.flowzbzl.flowbass.sPclass.Contains("15"))
            {
                m_mainform.flowzbzl.txtjct.Text = "5";
            }
            else if (m_mainform.flowzbzl.flowbass.iVax == 2)
            {
                m_mainform.flowzbzl.txtjct.Text = "1";
            }
            else
            {
                m_mainform.flowzbzl.txtjct.Text = "2";
            }
            //int.TryParse( m_mainform.flowzbzl.flowbass.m_iDetectID
            m_mainform.objyibiaobass.select("整备质量");
        }

        private void 地沟1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(sdetid))
            {
                MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                return;
            }
            if (objap1.flowbass.izhuangtai == 1)
            {
                MessageBox.Show("流水号" + objap1.flowbass.sDetectID + "正在检测，该工位状态忙碌中");
                return;
            }
            updatedpjyy(sdetid, com_czy.Text.Trim());
            objap1.flowbass.sDetectID = sdetid;
            objap1.flowbass.IsReadyForStart();
            objap1.start();
        }

        private void 地沟2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(sdetid))
            {
                MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                return;
            }
            if (objap2.flowbass.izhuangtai == 1)
            {
                MessageBox.Show("流水号" + objap2.flowbass.sDetectID + "正在检测，该工位状态忙碌中");
                return;
            }
            updatedpjyy(sdetid, com_czy.Text.Trim());
            objap2.flowbass.sDetectID = sdetid;
            objap2.flowbass.IsReadyForStart();
            objap2.start();
        }

        private void 地沟3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(sdetid))
            {
                MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                return;
            }
            if (objap3.flowbass.izhuangtai == 1)
            {
                MessageBox.Show("流水号" + objap3.flowbass.sDetectID + "正在检测，该工位状态忙碌中");
                return;
            }
            updatedpjyy(sdetid, com_czy.Text.Trim());
            objap3.flowbass.sDetectID = sdetid;
            objap3.flowbass.IsReadyForStart();
            objap3.start();
        }

        private void 下线ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (objap1.flowbass.izhuangtai == 1 && objap1.flowbass.sDetectID == sdetid)
            {
                objap1.flowbass.izhuangtai = 3;
            }
            else if (objap2.flowbass.izhuangtai == 1 && objap2.flowbass.sDetectID == sdetid)
            {
                objap2.flowbass.izhuangtai = 3;
            }
            else if (objap3.flowbass.izhuangtai == 1 && objap3.flowbass.sDetectID == sdetid)
            {
                objap3.flowbass.izhuangtai = 3;
            }
            else
            {
                MessageBox.Show("该车不在线上");
            }
        }

        private void 外廓整备ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (string.IsNullOrWhiteSpace(sdetid))
            {
                MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                return;
            }
            m_mainform.flowzbzl.flowbass.sDetectID = sdetid;
            m_mainform.flowzbzl.flowbass.IsReadyForStart();
            if (m_mainform.flowzbzl.flowbass.sPclass.Contains("挂") || m_mainform.flowzbzl.flowbass.sPclass.Contains("15"))
            {
                m_mainform.flowzbzl.txtjct.Text = "5";
            }
            else if (m_mainform.flowzbzl.flowbass.iVax == 2)
            {
                m_mainform.flowzbzl.txtjct.Text = "1";
            }
            else
            {
                m_mainform.flowzbzl.txtjct.Text = "2";
            }
            if (m_mainform.bsdb)
            {
                m_mainform.flowzbzl.txtjct.Text = "1";
            }
            //int.TryParse( m_mainform.flowzbzl.flowbass.m_iDetectID
            m_mainform.objyibiaobass.select("整备质量");
        }

        private void 动力性ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            m_mainform.bdiaodu = true;
            if (string.IsNullOrWhiteSpace(sdetid))
            {
                MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                return;
            }
            m_mainform.flowdlx.flowbass.sDetectID = sdetid;
            if (sdlxjy != "是")
            {
                MessageBox.Show("动力性检测免检");
                return;
            }
            m_mainform.objyibiaobass.select("动力性");
        }

        private void 油耗ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            m_mainform.bdiaodu = true;
            if (string.IsNullOrWhiteSpace(sdetid))
            {
                MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                return;
            }
            m_mainform.flowyh.flowbass.sDetectID = sdetid;
            if (syhjy != "是")
            {
                MessageBox.Show("油耗检测免检");
                return;

            }
            m_mainform.objyibiaobass.select("油耗");
        }
        public string ssx1 = "";
        public string ssx2 = "";
        public string ssx3 = "";

        public string sxx1 = "";
        public string sxx2 = "";
        public string sxx3 = "";
        public void showdp(flowAP fap)
        {
            if (fap == objap1)
            {
                ssx1 = fap.ssx;
                sxx1 = fap.sxx;
                showsx1();
                showxx1();
            }
            if (fap == objap2)
            {
                ssx2 = fap.ssx;
                sxx2 = fap.sxx;
                showsx2();
                showxx2();
            }
            if (fap == objap3)
            {
                ssx3 = fap.ssx;
                sxx3 = fap.sxx;
                showsx3();
                showxx3();
            }
        }

        private delegate void FlushClient();//代理
        private void showsx1()
        {
            if (this.txtap1sx.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(showsx1);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.txtap1sx.Text = string.Format(@"{0}", ssx1);
            }
        }
        private void showxx1()
        {
            if (this.txtap1xx.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(showxx1);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.txtap1xx.Text = string.Format(@"{0}", sxx1);
            }
        }
        private void showsx2()
        {
            if (this.txtap2sx.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(showsx2);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.txtap2sx.Text = string.Format(@"{0}", ssx2);
            }
        }
        private void showxx2()
        {
            if (this.txtap2xx.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(showxx2);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.txtap2xx.Text = string.Format(@"{0}", sxx2);
            }
        }
        private void showsx3()
        {
            if (this.txtap3sx.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(showsx3);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.txtap3sx.Text = string.Format(@"{0}", ssx3);
            }
        }
        private void showxx3()
        {
            if (this.txtap3xx.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(showxx3);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.txtap3xx.Text = string.Format(@"{0}", sxx3);
            }
        }

        private void 尾气上线ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void skinButton2_Click(object sender, EventArgs e)
        {

            string sstart = datestart2.Value.ToString("yyyy-MM-dd 00:00:00");
            string send = dateend2.Value.ToString("yyyy-MM-dd 23:59:59");
            m_mainform.objbass = m_mainform.objbass3in1;
            getjiluSQL(text_hphm2.Text, true, skinDataGridView_wqdj, sstart, send);//获取登录车辆上线
        }

        private void skinButton8_Click(object sender, EventArgs e)
        {

            m_mainform.bdiaodu = true;
            mainform.methodId = methodId;
            mainform.shphm = shphm;
            m_mainform.sobdshifou = sobdshifou;
            mainform.businessId = businessId;
            m_mainform.sfOBD = false;
            m_mainform.InspectionOperator = skinCom_czy2.Text;
            m_mainform.InspectionDriver = skinCom_ycy2.Text;
            //baocunCLXX(string hphm, string hpzl, string edgl, string edzs, string jzzl,string cllx)
            m_mainform.objbass.sendOBDJCJG(businessId);
            m_mainform.objbass.baocunclexxyj(businessId);//冯文健加
            m_mainform.objbass.getstandxz(businessId);
            m_mainform.objbass.setclxx(businessId);//获取车辆信息 邦元的必须放在获取限值后面
            //objbass.getstandxz(shphm, shpzl, skinCom_ycy.Text, skinCom_czy.Text);//获取限值
            m_mainform.StartTest(methodId);
        }

        private void skinDataGridView1_SelectionChanged(object sender, EventArgs e)
        {

            try
            {
                businessId = this.skinDataGridView_wqdj.CurrentRow.Cells[0].Value.ToString();
                methodId = this.skinDataGridView_wqdj.CurrentRow.Cells[3].Value.ToString();
                shphm = this.skinDataGridView_wqdj.CurrentRow.Cells[1].Value.ToString();
                shpzl = this.skinDataGridView_wqdj.CurrentRow.Cells[2].Value.ToString();
                jccs = this.skinDataGridView_wqdj.CurrentRow.Cells[5].Value.ToString();
                testtimes = this.skinDataGridView_wqdj.CurrentRow.Cells[5].Value.ToString();
                if (this.skinDataGridView_wqdj.CurrentRow.Cells[4].Value.ToString().Trim().Length > 0)
                {
                    sobdshifou = "1";
                }
                else
                {
                    sobdshifou = "0";
                }

                if (methodId.Contains("WT") || methodId.Contains("ASM") || methodId.Contains("LD") || methodId.Contains("加载"))//ASM
                {
                    sgkfjc = "1";
                }
                else
                {
                    sgkfjc = "0";
                }

            }
            catch
            {
            }
        }

        private void skinTabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {
            string text = ((TabControl)sender).TabPages[e.Index].Text;
            SolidBrush brush = new SolidBrush(Color.Black);
            StringFormat sf = new StringFormat(StringFormatFlags.DirectionRightToLeft);
            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment = StringAlignment.Center;
            e.Graphics.DrawString(text, SystemInformation.MenuFont, brush, e.Bounds, sf);
        }
        public void bcclxx(string jylsh)//智慧环保
        {
            try
            {
                string hp = "";
                string zl = "";
                string gl = "";
                string zs = "";
                float jz = 0;
                string lx = "";
                float lcb = 0;
                string sql = string.Format(@"select * from SHWD_GetGas where jcCarCheckSerialNumber ='{0}'", jylsh);
                DataTable dt = m_mainform.objbass.objdb.GetTable(sql);
                if (dt.Rows.Count > 0)
                {
                    hp = dt.Rows[0]["jcCarBrandNumber"].ToString().Trim();
                    zl = dt.Rows[0]["jcCarBrandTypeNum"].ToString().Trim();
                    gl = dt.Rows[0]["enginepower"].ToString().Trim();
                    zs = dt.Rows[0]["enginespeed"].ToString().Trim();
                    float fzs = 0;
                    float.TryParse(zs, out fzs);
                    zs = fzs.ToString("0");
                    float.TryParse(dt.Rows[0]["zbzl"].ToString(), out jz);
                    if (jz > 0)
                    {
                        jz += 100;
                    }
                    lx = dt.Rows[0]["jcCarType"].ToString().Trim();
                    float.TryParse(dt.Rows[0]["odometer"].ToString(), out lcb);
                    m_mainform.odometer = lcb.ToString("0");
                    m_mainform.jcffdh = dt.Rows[0]["JcCarCheckMethodNum"].ToString().Trim();
                    string srrlz = dt.Rows[0]["jcCarFuelCategory"].ToString().Trim();
                    m_mainform.baocunCLXX(hp, zl, gl, zs, jz.ToString(), lx, srrlz);
                }
            }
            catch
            {
            }
        }
        private void skinDataGridView_wj_MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                businessId = this.skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString();
                methodId = this.skinDataGridView_wj.CurrentRow.Cells[3].Value.ToString();
                shphm = this.skinDataGridView_wj.CurrentRow.Cells[1].Value.ToString();
                shpzl = this.skinDataGridView_wj.CurrentRow.Cells[2].Value.ToString();
                jccs = this.skinDataGridView_wj.CurrentRow.Cells[5].Value.ToString();
                testtimes = this.skinDataGridView_wj.CurrentRow.Cells[5].Value.ToString();
                obdzt = this.skinDataGridView_wj.CurrentRow.Cells[4].Value.ToString();
                if (this.skinDataGridView_wj.CurrentRow.Cells[4].Value.ToString().Trim().Length > 0)
                {
                    sobdshifou = "1";
                }
                else
                {
                    sobdshifou = "0";
                }

                if (methodId.Contains("WT") || methodId.Contains("ASM") || methodId.Contains("LD") || methodId.Contains("加载"))//ASM
                {
                    sgkfjc = "1";
                }
                else
                {
                    sgkfjc = "0";
                }

            }
            catch
            {
                businessId = "";
                methodId = "";
                shphm = "";
                shpzl = "";
                jccs = "";
                testtimes = "";
                obdzt = "";
            }
        }

        private void skinCom_czy_SelectedIndexChanged(object sender, EventArgs e)
        {
            m_mainform.sczyxx = skinCom_czy.Text;
        }

        private void skinButton6_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(true);
        }

        private void skinButton7_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(false);
        }

        private void dgvzongjian_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            int rowIndex = e.RowIndex;
            int columnIndex = e.ColumnIndex;

            if (rowIndex != -1 && columnIndex != -1)
            {
                dgvzongjian.CurrentCell = dgvzongjian.Rows[rowIndex].Cells[columnIndex];
            }

            try
            {
                sdetid = "";
                sdlxjy = "";
                syhjy = "";
                sdetid = this.dgvzongjian.CurrentRow.Cells[0].Value.ToString();
                sdlxjy = this.dgvzongjian.CurrentRow.Cells[3].Value.ToString();
                syhjy = this.dgvzongjian.CurrentRow.Cells[4].Value.ToString();
                sptjylsh = "";
                sptjylsh = this.dgvzongjian.CurrentRow.Cells[9].Value.ToString();
                zjhphm = this.dgvzongjian.CurrentRow.Cells[1].Value.ToString();
                zjhpzl = this.dgvzongjian.CurrentRow.Cells[2].Value.ToString();
            }
            catch
            {
            }

        }

        private void 过程数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (skinDataGridView_wj.CurrentRow.Selected)
            {
                guochengshuju obj = new guochengshuju();
                obj.m_mainform = m_mainform;
                obj.sqjlsh = skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString();
                obj.sqjhphm = skinDataGridView_wj.CurrentRow.Cells[1].Value.ToString();
                obj.sqjjcff = skinDataGridView_wj.CurrentRow.Cells[3].Value.ToString();
                obj.ShowDialog();
            }
        }

        private void oBD过程ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (skinDataGridView_wj.CurrentRow.Selected)
            {
                guochengshuju obj = new guochengshuju();
                obj.m_mainform = m_mainform;
                obj.sqjlsh = skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString();
                obj.sqjhphm = skinDataGridView_wj.CurrentRow.Cells[1].Value.ToString();
                obj.sqjjcff = "OBD";
                obj.ShowDialog();
            }
        }

        private void 设计ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            报告单.baogaodanbass obj = new 报告单.baogaodanbass();
            if (methodId.Contains("DB") || methodId.Contains("双怠速"))//shaungdaishu双怠速
            {
                obj = new 报告单.qiyou();
                obj.m_mainform = m_mainform;
                obj.bgd("", skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString(), "", "1");
            }
            else if (methodId.Contains("WT") || methodId.Contains("ASM"))//ASM
            {
                obj = new 报告单.qiyou();
                obj.m_mainform = m_mainform;
                obj.bgd("", skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString(), "", "1");
            }
            else if (methodId.Contains("LD") || methodId.Contains("加载"))//LUG
            {
                obj = new 报告单.caiyou();
                obj.m_mainform = m_mainform;
                obj.bgd("", skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString(), "", "1");
            }
            else if (methodId.Contains("TG") || methodId.Contains("自由"))//ZYJS
            {
                obj = new 报告单.caiyou();
                obj.m_mainform = m_mainform;
                obj.bgd("", skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString(), "", "1");
            }
        }

        private void 预览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            报告单.baogaodanbass obj = new 报告单.baogaodanbass();
            if (methodId.Contains("DB") || methodId.Contains("双怠速"))//shaungdaishu双怠速
            {
                obj = new 报告单.qiyou();
                obj.m_mainform = m_mainform;
                obj.bgd("", skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString(), "", "2");
            }
            else if (methodId.Contains("WT") || methodId.Contains("ASM"))//ASM
            {
                obj = new 报告单.qiyou();
                obj.m_mainform = m_mainform;
                obj.bgd("", skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString(), "", "2");
            }
            else if (methodId.Contains("LD") || methodId.Contains("加载"))//LUG
            {
                obj = new 报告单.caiyou();
                obj.m_mainform = m_mainform;
                obj.bgd("", skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString(), "", "2");
            }
            else if (methodId.Contains("TG") || methodId.Contains("自由"))//ZYJS
            {
                obj = new 报告单.caiyou();
                obj.m_mainform = m_mainform;
                obj.bgd("", skinDataGridView_wj.CurrentRow.Cells[0].Value.ToString(), "", "2");
            }
        }
        public static string yeid = "";//中科宇图OBD流水号
        public bool obdxg = false;//修改OBD状态
        private void 上传OBD数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            m_mainform.objbass.baocunclexxyj(businessId);
            {
                //MessageBox.Show("准备上传OBD");

                string sql = string.Format(@"select  TOP (1) *  from zkOBD where cphm='{0}'order by clxxid desc", shphm);
                DataTable dt = m_mainform.objbass.objdb.GetTable(sql);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        yeid = dt.Rows[i]["yewid"].ToString().Trim();

                    }
                }

                m_mainform.objbass.XXTZ("08");
                m_mainform.objbass.OBDJC();
                m_mainform.objbass.OBDYQ();
                m_mainform.objbass.sendOBDJCJG(yeid, businessId, obdxg);
                m_mainform.objbass.OBDYQ();
            }

        }

        private void 发送OBDToolStripMenuItem_Click(object sender, EventArgs e)
        {
            obdxg = true;
        }

        private void diaodu_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F6)
            {
                发送OBDToolStripMenuItem.Visible = true;
            }
        }

        private void diaodu_KeyUp(object sender, KeyEventArgs e)
        {
            发送OBDToolStripMenuItem.Visible = false;
        }

        private void skinButton9_Click(object sender, EventArgs e)
        {

//            dgvzongjian.Rows.Clear();
//            string ssql = string.Format(@"SELECT * from dbo.AUTO,dbo.Detects_SJA where dbo.AUTO.AT_ID=Detects_SJA.AT_ID 
// and Detects_SJA.DET_DATE>'{0}' and Detects_SJA.DET_DATE<dateadd(day,1,'{1}') and AUTO.AT_HPHM like '%{2}%' order by Detects_SJA.DETECT_ID",
//dateTimePicker2.Value.ToString("yyyy-MM-dd"), dateTimePicker1.Value.ToString("yyyy-MM-dd"), textBox1.Text);

//            DataTable dt = m_mainform.objbass.objdb.GetTable(ssql);
//            int count = 0;
//            if (dt.Rows.Count > 0)
//            {
//                foreach (DataRow dr in dt.Rows)
//                {

//                    if (dr["DET_BJYXM"].ToString().Trim().Contains("M1") || dr["DET_BJYXM"].ToString().Trim().Contains("Z1"))
//                    {
//                        int iitem = 0;
//                        if (!int.TryParse(dr["DET_JYCS"].ToString().Trim(), out iitem))
//                            iitem = 0;
//                        this.dgvzongjian.Rows.Add();
//                        this.dgvzongjian.Rows[count].Cells[0].Value = dr["DETECT_ID"].ToString().Trim();    //填充第一列的数据 
//                        this.dgvzongjian.Rows[count].Cells[1].Value = dr["AT_HPHM"].ToString().Trim();    //填充第二列的数据 
//                        this.dgvzongjian.Rows[count].Cells[2].Value = dr["AT_HPZL"].ToString().Trim();    //填充第二列的数据 
//                        this.dgvzongjian.Rows[count].Cells[3].Value = "否";     //填充第二列的数据 
//                        this.dgvzongjian.Rows[count].Cells[4].Value = "否";     //填充第二列的数据 
//                        this.dgvzongjian.Rows[count].Cells[6].Value = dr["DET_BJYXM"].ToString().Trim().Contains("M1") ? "是" : "否";
//                        if (dr["DET_EJYXM"].ToString().Trim().Contains("M1"))
//                        {
//                            this.dgvzongjian.Rows[count].Cells[6].Style.ForeColor = Color.Red;
//                        }
//                        this.dgvzongjian.Rows[count].Cells[7].Value = dr["DET_BJYXM"].ToString().Trim().Contains("Z1") ? "是" : "否";
//                        if (dr["DET_EJYXM"].ToString().Trim().Contains("Z1"))
//                        {
//                            this.dgvzongjian.Rows[count].Cells[7].Style.ForeColor = Color.Red;
//                        }
//                        this.dgvzongjian.Rows[count].Cells[5].Value = iitem;    //填充第二列的数据 
//                        this.dgvzongjian.Rows[count].Cells[8].Value = "否";     //填充第二列的数据 
//                        count++;
//                    }
//                }
//                if (count > 0)
//                {
//                    try
//                    {
//                        sdetid = this.dgvzongjian.Rows[0].Cells[0].Value.ToString();
//                        sdlxjy = this.dgvzongjian.Rows[0].Cells[3].Value.ToString();
//                        syhjy = this.dgvzongjian.Rows[0].Cells[4].Value.ToString();
//                        sdetid = "";
//                        sdlxjy = "";
//                        syhjy = "";
//                    }
//                    catch (Exception)
//                    {
//                        throw;
//                    }
//                }
//                else
//                {
//                    MessageBox.Show("该工位查询记录为空");
//                }

//            }
//            else
//            {
//                MessageBox.Show("查询记录为空");
//            }

        }

        private void 动态开始ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (string.IsNullOrWhiteSpace(sdetid))
            {
                MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                return;
            }

            WebReferenceAJ.Service objweb = new WebReferenceAJ.Service();
            objweb.Url = m_mainform.sweburl;
            string msg = objweb.writeObjectOut2(sptjylsh, "", zjhpzl, zjhphm, "0,0", "DC", "开始", "", "1", comboBox1.Text, "1");//
            if (msg.Contains("<code>1</code>"))
            {
                MessageBox.Show("发送动态开始成功");
            }
            else
            {
                MessageBox.Show(msg);
            }
        }

        public void iniYCYzj()
        {
            string ssqlex = "";
            //ssqlex = string.Format(@"select * from {0}", dataname);
            ssqlex = string.Format(@"select * from USERE");
            DataTable dt = m_mainform.objbass.objdb.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                comboBox2.Items.Add(dt.Rows[i]["NAME"].ToString().Trim());
                //skinCom_ycy.Items.Add(dt.Rows[i]["name"].ToString().Trim());
                if (i == 0)
                    comboBox2.Text = dt.Rows[0]["NAME"].ToString().Trim();
                //skinCom_ycy.Text = dt.Rows[0]["name"].ToString().Trim();
            }
        }

        private void 动态结束ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {

            if (string.IsNullOrWhiteSpace(sdetid))
            {
                MessageBox.Show("流水号不能为空！请选择车辆流水号！");
                return;
            }
            if (string.IsNullOrWhiteSpace(comboBox2.Text.Trim()))
            {
                MessageBox.Show("引车员不能为空！请选择引车员！");
                return;
            }

            string sql = string.Format(@"select * from USERE where NAME='{0}' ", comboBox2.Text.Trim());
            string sid = "";
            DataTable dt = m_mainform.objbass.objdb.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                sid = dt.Rows[0]["YHLB"].ToString().Trim();
            }
            else
            {
                MessageBox.Show("找不到该引车员");
                return;
            }

            WebReferenceAJ.Service objweb = new WebReferenceAJ.Service();
            objweb.Url = m_mainform.sweburl;

            objweb.SendWriteObjectOut(sptjylsh, "1,1,1,1,1,1,1,1,1", "912", sid, "", "", "");

            string msg = objweb.writeObjectOut2(sptjylsh, "", zjhpzl, zjhphm, "0,0", "DC", "结束", "", "1", comboBox1.Text, "1");//
            if (msg.Contains("<code>1</code>"))
            {
                MessageBox.Show("发送动态结束成功");
            }
            else
            {
                MessageBox.Show(msg);
            }
        }

        public void getdongtai()
        {

            string path = System.Windows.Forms.Application.StartupPath + "\\工位配置.ini";
            string path1 = string.Format(@"{0}", path);
            iniclass objini = new iniclass();
            objini.Ini(path1);
            bool bdongtai = objini.ReadValue("工位配置", "动态使用工位机控制") == "是" ? true : false;
            if (bdongtai)
            {
                setdongtai(true);
            }
            else
            {

                setdongtai(false);
            }
            //cheddg.Checked = objini.ReadValue("工位配置", "启用多地沟") == "是" ? true : false;
        }
        public void setdongtai(bool bqy)
        {
            动态线号.Visible = bqy;
            comboBox1.Visible = bqy;
            skinLabel14.Visible = bqy;
            comboBox2.Visible = bqy;
            动态开始ToolStripMenuItem.Visible = bqy;
            动态结束ToolStripMenuItem.Visible = bqy;
        }
        public void updatedpjyy(string slsh, string sdpczy)
        {
            string ssqlex = "";
            ssqlex = string.Format(@"update Detects_SJA set DET_DPCZY='{0}' where DETECT_ID={1}", sdpczy, slsh);
            m_mainform.objbass.objdb.InsertDB(ssqlex);
        }
    }
}
